package com.qujia.station.controller;

import com.qujia.common.annotation.Log;
import com.qujia.common.core.controller.BaseController;
import com.qujia.common.core.domain.AjaxResult;
import com.qujia.common.core.domain.model.LoginUser;
import com.qujia.common.core.page.TableDataInfo;
import com.qujia.common.enums.BusinessType;
import com.qujia.common.utils.SecurityUtils;
import com.qujia.system.service.IGzhNewsTemplateService;
import com.qujia.system.domain.GzhNewsTemplate;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 油站信息Controller
 *
 * @author qujia
 * @date 2020-12-08
 */
@Api("公众号模板")
@RestController
@RequestMapping("/gzhNewsTemplate/info")
public class GzhNewsTemplateController extends BaseController
{
    @Autowired
    private IGzhNewsTemplateService gzhNewsTemplateService;
    /**
     * 查询模板消息集合
     */
    @ApiOperation("公众号查询list")
    @ApiImplicitParam(name = "gzhNewsTemplate", value = "公众号查询list", dataType = "GzhNewsTemplate")
    @GetMapping("/listTemplate")
    public TableDataInfo list(GzhNewsTemplate gzhNewsTemplate)
    {
        LoginUser current=SecurityUtils.getLoginUser();
        if("1".equals(current.getUser().getUserLevel())){
            gzhNewsTemplate.setStationId(current.getUser().getEnterpriseId());
        }else if("0".equals(current.getUser().getUserLevel())){

        }else {
            List<GzhNewsTemplate> gzhNewsTemplates1=new ArrayList<>();
            return getDataTable(gzhNewsTemplates1);
        }
        startPage();
        List<GzhNewsTemplate> gzhNewsTemplates = gzhNewsTemplateService.selectGzhNewsTemplateList(gzhNewsTemplate);
        return getDataTable(gzhNewsTemplates);
    }

    /**
     * 增加模板消息
     */
    @ApiOperation("增加模板消息")
    @ApiImplicitParam(name = "gzhNewsTemplate", value = "增加模板消息", dataType = "GzhNewsTemplate")
    @Log(title = "增加模板消息", businessType = BusinessType.INSERT)
    @PostMapping(value = "/addTemplate")
    public AjaxResult addTemplate(@RequestBody GzhNewsTemplate gzhNewsTemplate)
    {

        return toAjax(gzhNewsTemplateService.insertGzhNewsTemplate(gzhNewsTemplate));
    }



    /**
     * 获取模板详细消息
     */
    @ApiOperation("获取模板详细消息")
    @ApiImplicitParam(name = "id", value = "模板消息", required = true, dataType = "Long", paramType = "path")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        GzhNewsTemplate gzhNewsTemplate=gzhNewsTemplateService.selectGzhNewsTemplateById(id);
        return AjaxResult.success(gzhNewsTemplate);
    }

    /**
     * 修改模板信息
     */
    @ApiOperation("修改模板信息")
    @ApiImplicitParam(name = "gzhNewsTemplate", value = "修改模板信息", dataType = "GzhNewsTemplate")
    @Log(title = "修改模板消息", businessType = BusinessType.UPDATE)
    @PutMapping(value = "/updateTemplate")
    public AjaxResult edit(@RequestBody GzhNewsTemplate gzhNewsTemplate)
    {

        return toAjax(gzhNewsTemplateService.updateGzhNewsTemplate(gzhNewsTemplate));
    }



}
